import type { BIGINT_PG, ExtIdTuple, INTEGER_PG, SMALLINT_PG, VARCHAR50_PG } from "~/db.pg";
import { ExtIntro } from "~/extend";

/** 交易对象分组 */
export type TickGroup = ExtIdTuple & {
  name: VARCHAR50_PG;
  code: VARCHAR50_PG;
  joinTickSymbolList?: TickSymbol[];
  joinTickMinuteList?: TickMinute[];
};

/** 交易对象 */
export type TickSymbol = ExtIdTuple & {
  name: VARCHAR50_PG;
  code: VARCHAR50_PG;
  refTickGroupId: TickGroup["id"];
} & {
  justTickGroup?: TickGroup;
  joinTickMinuteList?: TickMinute[];
};

/** 单位分钟内的成交数据 */
export type TickMinute = ExtIdTuple & {
  name: VARCHAR50_PG;
  code: VARCHAR50_PG;
  refTickGroupId: TickGroup["id"];
  refTickSymbolId: TickSymbol["id"];

  /** 具体交易时间 */
  deliveryTime: BIGINT_PG;
  deliveryYear: SMALLINT_PG;
  deliveryMonth: SMALLINT_PG;
  deliveryWeekDay: SMALLINT_PG;
  deliveryHour: SMALLINT_PG;
  deliveryMinute: SMALLINT_PG;

  /** 成交数量（多少股？多少个BTC？）*/
  volumn: BIGINT_PG;

  /** 成交资金 */
  turnover: BIGINT_PG;

  /** 成交笔数 */
  trades: INTEGER_PG;

  /** 平均成交价格（成交资金/成交笔数）*/
  priceAvg: BIGINT_PG;

  /** 价格波动（最高-最低）*/
  priceChange: BIGINT_PG;
} & {
  justTickGroup?: TickGroup;
  justTickSymbol?: TickSymbol;
};
